

*------------------------------------------------------------------------------------
* Table 2 -- Timing of Treatment Impacts on Support for Refugee Integration Policies
*------------------------------------------------------------------------------------

	gen b_survey_date = dofc(b_starttime)
	
**** Run regressions and get coefficients

** Domain 1: Support for inclusive refugee hosting // Baseline, Midline, Endline, Endline2
	forval i = 1/5 {
		gen domain1_coef`i' = . 	// to store coefficients
		gen domain1_ll`i' = . 		// to store 95% confidence interval lower bound
		gen domain1_ul`i' = . 		// to store 95% confidence interval upper bound
		gen domain1_wv`i' = .
	}
	
	local num = 1	
	foreach wv of numlist 0 1 2 4 {
		* Regression for Baseline
		if (`wv' == 0) {
			local exclude lik_b_j1 lik_b_j2 lik_b_j3 lik_b_j4 lik_b_j5 lik_b_j6 lik_b_j7 lik_b_j8
			local temp_lik_list : list global(lik_list) - exclude // don't include dimension of heterogeneity in lasso controls
			
			pdslasso b_domain1 ib6.treatment (i.strata phone_survey b_survey_date $cat_list `temp_lik_list' $con_list) if wave_flag == 1, partial(i.strata phone_survey b_survey_date) post(pds) robust cluster(ent_id) lopt(prestd)			
		}
		
		* Regression for Midline, Endline, Endline2
		if !(`wv' == 0) {
			pdslasso e_domain1 ib6.treatment (i.strata phone_survey survey_date b_domain1 $cat_list $lik_list $con_list) if wave == `wv', partial(i.strata phone_survey survey_date b_domain1) post(pds) robust cluster(ent_id) lopt(prestd)
		}
		
		eststo e_domain1_wv`wv'
		
		* Store coefficients for plot
		mat domain1_wv`wv' = r(table)
		local num2 = 0 	// for plotting purpose
		foreach i of numlist 5 3 4 2 1 { 	// Cash+Info, Cash, Info, R-Mentee, U-Mentee
			if `wv' == 0 local x_num = 1 + (`num2' - 1)/5
			if `wv' == 1 local x_num = 12 + (`num2' - 1)/5
			if `wv' == 2 local x_num = 19 + (`num2' - 1)/5
			if `wv' == 4 local x_num = 29 + (`num2' - 1)/5
			replace domain1_wv`i' = `x_num' 					in `num'	
			replace domain1_coef`i' = domain1_wv`wv'[1, `i'] 	in `num'
			replace domain1_ll`i' = domain1_wv`wv'[5, `i'] 		in `num'
			replace domain1_ul`i' = domain1_wv`wv'[6, `i'] 		in `num'
			local ++num2
		}
		local ++num
	}
	
	cap drop x upper lower x2 zero
	local lower = -0.23
	local upper =  0.44
	
	gen x = _n if _n <= 30
	gen upper = `upper' - 0.005
	gen lower = `lower' + 0.005
	
	gen x2 = _n - 1 if _n <= 32
	gen zero = 0
		
	forvalues i = 1 / 5 {
		replace domain1_ll`i' = `lower' if domain1_ll`i' < `lower'
		replace domain1_ul`i' = `upper' if domain1_ul`i' > `upper'
	}
	
	graph set window fontface "Arial"

	mylabels -0.2(0.2)0.4, format(%03.1f) clean local(ylabels)
	twoway (rarea upper lower x if inrange(x,3,5), bcolor(gs14) plotregion(margin(0.1 0.1 0.1 0.1))) /// 1
		(rarea upper lower x if inrange(x,17,19), bcolor(gs14) plotregion(margin(0.1 0.1 0.1 0.1))) /// 2 
		(line zero x2, lc(black) lw(medium) plotregion(margin(0 0 0 0))) /// 3 
		(connect domain1_coef1 domain1_wv1, m(diamond_hollow) msize(small) mc(orange_red) lc(orange_red) lp("-") lw(thin)) /// 4: U-M
		(rcap domain1_ul2 domain1_ll2 domain1_wv2, lc(khaki) lp(solid) lw(vthin)) /// 5: R-M
		(connect domain1_coef2 domain1_wv2, m(diamond) msize(medium) mc(khaki) lc(khaki) lp(solid) lw(medthick)) /// 6: R-M
		(connect domain1_coef3 domain1_wv3, m(circle_hollow) msize(small) mc(sienna)  lc(sienna) lp("-") lw(thin)) /// 7: Cash 
		(rcap domain1_ul4 domain1_ll4 domain1_wv4, lc(midblue) lp(solid) lw(vthin)) /// 8: Info
		(connect domain1_coef4 domain1_wv4, m(square) msize(medium) mc(midblue) lc(midblue) lp(solid) lw(medthick)) /// 9: Info
		(rcap domain1_ul5 domain1_ll5 domain1_wv5, lc(dkgreen) lp(solid) lw(vthin)) /// 10: Labeled Grant
		(connect domain1_coef5 domain1_wv5, m(circle) msize(medium) mc(dkgreen) lc(dkgreen) lp(solid) lw(medthick)), /// 11: Labeled Grant
		scheme(s1mono) title("" " ", size(12pt)) ///
		xlabel(1 `""Nov" "2019  ""' 3 `""Jan" "  2020""' 12 `""Oct" "2020""' 17 `""Mar" "2021  ""' 19 `""May" "  2021""' 29 `""Mar" "2022""') xtitle("") ytitle("Integration Policies Index" "Treatment Effects (Std. Dev.)" " ") yscale(r(`lower' `upper')) ylabel(`ylabels')  ///
		legend(order(11 "Info. + Labeled Grant" 7 "Grant Only" 9 "Information Only" 4 "Mentored by Ugandan" 6 "Mentored by Refugee" 1 "Interventions") cols(2) region(ls(none)))
		
graph export "$path/Output/Fig2.eps", replace
	
	drop b_survey_date - zero
